package com.aegean.CommercialHotelBookSystem.shop.action;

import java.io.IOException;
import java.util.ArrayList;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.aegean.CommercialHotelBookSystem.factory.BusinessFactory;
import com.aegean.CommercialHotelBookSystem.model.Customer;
import com.aegean.CommercialHotelBookSystem.model.Room;
import com.aegean.CommercialHotelBookSystem.shop.business.IShopBusiness;

/**
 * Servlet implementation class OrderService
 */
public class ShopOrderConfirm extends HttpServlet {
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		HttpSession session = request.getSession();
		ArrayList<Room> shopcar = (ArrayList<Room>) session
				.getAttribute("Shop_BuyCar");
		Customer customer = (Customer) session.getAttribute("Login_User");
		IShopBusiness business = BusinessFactory.createShopBusiness();
		boolean result = business.addOrder(shopcar, customer);
		if (result == true) {
			shopcar.clear();
			session.setAttribute("Shop_BuyCar", shopcar);
			request.getRequestDispatcher("/User/User_bookTide.action").forward(
					request, response);
		} else {
			request.getRequestDispatcher("Shop_Books.jsp").forward(request,
					response);
		}
	}
}
